package org.javaboy.demo;

import org.javaboy.consumer.RoleService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Demo02 {
    /**
     * 兄弟容器演示
     *
     * 兄弟容器之间是互相独立的，互相不能访问对方容器中的 bean
     *
     * @param args
     */
    public static void main(String[] args) {
        //这个作为兄弟共同的 parent
        ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext();
        ClassPathXmlApplicationContext consumerCtx = new ClassPathXmlApplicationContext("consumer_beans.xml");
        ClassPathXmlApplicationContext merchantCtx = new ClassPathXmlApplicationContext("merchant_beans.xml");
        consumerCtx.setParent(parent);
        merchantCtx.setParent(parent);
        parent.refresh();
        //parent 中不能访问子容器中的 bean
//        RoleService rs1 = parent.getBean(RoleService.class);
//        System.out.println("rs1 = " + rs1);
        org.javaboy.demo.merchant.RoleService rs = consumerCtx.getBean(org.javaboy.demo.merchant.RoleService.class);
        System.out.println("rs = " + rs);
    }
}
